package org.teamh.connection.json.command;

import org.teamh.game.Start;


public class JsonSender {
	
	private static Start start;
	
	public static void noop() {
		JsonCommandObject json = new JsonCommandObject("NOOP");
		start.getConnection().sendMessage(json.jsonToString());
	}
	
	public static void startGame() {
		JsonCommandObject json = new JsonCommandObject("START_GAME");
		start.getConnection().sendMessage(json.jsonToString());
	}
	
	public static void leaveGame() {
		JsonCommandObject json = new JsonCommandObject("LEAVE_GAME");
		start.getConnection().sendMessage(json.jsonToString());
	}
	
	public static void chatWithAll(String message) {
		JsonCommandObject json = new JsonCommandObject("MESSAGE");
		json.addEntry("message", message);
		start.getConnection().sendMessage(json.jsonToString());	
	}
	
	public static void chatWithUser(String message, String to) {
		JsonCommandObject json = new JsonCommandObject("MESSAGE");
		json.addEntry("message", message);
		json.addEntry("audience", "USER");
		json.addEntry("recipient", to);
		start.getConnection().sendMessage(json.jsonToString());	
	}
	
	public static void chatWithTeam(String message, String to) {
		JsonCommandObject json = new JsonCommandObject("MESSAGE");
		json.addEntry("message", message);
		json.addEntry("audience", "TEAM");
		json.addEntry("recipient", to);
		start.getConnection().sendMessage(json.jsonToString());	
	}
	
	public static void changeColor(String color) {
		JsonCommandObject json = new JsonCommandObject("CHANGE_USER_COLOR");
		json.addEntry("color", color);
		start.getConnection().sendMessage(json.jsonToString());
	}
	
	public static void chooseTile(String tile) {
		JsonCommandObject json = new JsonCommandObject("CHOOSE_TILE");
		json.addEntry("tile", tile);
		start.getConnection().sendMessage(json.jsonToString());
	}
	
	public static void createTower(String towerType, String cell) {
		JsonCommandObject json = new JsonCommandObject("CREATE_TOWER");
		json.addEntry("towertype", towerType);
		json.addEntry("cell", cell);
		start.getConnection().sendMessage(json.jsonToString());
	}
	
	public static void sellTower(String tower) {
		JsonCommandObject json = new JsonCommandObject("SELL_TOWER");
		json.addEntry("tower", tower);
		start.getConnection().sendMessage(json.jsonToString());
	}
	
	public static void upgradeTower(String tower, String level) {
		JsonCommandObject json = new JsonCommandObject("UPGRADE_TOWER");
		json.addEntry("tower", tower);
		json.addEntry("level", level);
		start.getConnection().sendMessage(json.jsonToString());
	}
	
	public static void changeTowerStrategy(String tower, String strategy) {
		JsonCommandObject json = new JsonCommandObject("CHANGE_TOWER_STRATEGY");
		json.addEntry("tower", tower);
		json.addEntry("strategy", strategy);
		start.getConnection().sendMessage(json.jsonToString());
	}
	
	public static void createCreep(String creepType) {
		JsonCommandObject json = new JsonCommandObject("CREATE_CREEP");
		json.addEntry("creeptype", creepType);
		start.getConnection().sendMessage(json.jsonToString());
	}

	public static void setStart(Start start) {
		JsonSender.start = start;
	}
}
